package com.tc.zigbee.mt;

import java.util.LinkedList;
import java.util.List;

import com.tc.gateway.GroupManager;
import com.tc.gateway.SceneManager;
import com.tc.gateway.device.GeneralDevice;
import com.tc.gateway.device.Scene;
import com.tc.zigbee.entity.Endpoint;
import com.tc.zigbee.entity.device.ZigbeeDevice;
import com.tc.zigbee.mt.request.RequestFactory;
import com.tc.zigbee.zcl.ZclCommandCreator;
import com.tc.zigbee.zcl.ZclConstants;

public class ZigbeeSceneManager implements SceneManager {
	ZigbeeManager manager;
	public ZigbeeSceneManager(ZigbeeManager zm){
		manager = zm;
	}
	public void recall(byte id) {
		Scene scene = manager.getScenes().get(id);
		for(GeneralDevice d : scene.getParent().getMembers()){
			Endpoint e = ((ZigbeeDevice)d).getEndpoint();
			byte[] c = ZclCommandCreator.recallScene((byte)0, scene.getGroup(), scene.getScene());
			MtCommand mc = RequestFactory.MtAfDataRequest(
					(byte) 2, 
					e.getParent()
					.getNwkAddress(),

					e.getEndpointId(), 
					(byte) manager.remoteControl
					.getEndpointId(), 
					(short) ZclConstants.ZCL_CLUSTER_ID_GEN_SCENES, 
					(byte) 0,
					(byte) 0, 
					(byte) 2,
					(byte) c.length, 
					c);
			RequestQueue.offer(mc);
		}
		
	}

	public List<Scene> getAll() {
		// TODO Auto-generated method stub
		return new LinkedList(manager.scenes.values());
	}
	
		
}
